<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="UTF-8">
<head>
    <meta charset="UTF-8">
    <title> XXX送水公司后台管理系统</title>

    <!--Bootstrap固定框架-->
    <link rel='stylesheet' th:href="@{/webjars/bootstrap/3.3.7/css/bootstrap.css}">
    <link rel='stylesheet' th:href="@{/webjars/bootstrap/3.3.7/css/bootstrap-theme.css}">
    <!--图标库-->
    <link rel='stylesheet' th:href='@{/css/material-design-iconic-font.min.css}'>
    <!--核心样式-->
    <link rel="stylesheet" th:href="@{/css/style.css}">
    <!--jQuery-->
    <script th:src="@{/webjars/jquery/3.3.1/jquery.js}"></script>
    <script>
        $(function () {
            //全选/全否的动作安排
            $("#selectAll").click(function () {
                $("input[name=chkHistory]").prop("checked",$("#selectAll").prop("checked"))
            })
            //批量删除按钮操作
            $("#batchDeleteHistory").click(function () {
                //处理数据
                let checkedList = $("input[name=chkHistory]:checked")
                if (checkedList.length == 0){
                    alert("请至少选择一个再进行删除~")
                    return;
                }
                let idList = "";
                $(checkedList).each(function () {
                    idList += ","+$(this).val();
                })

                if(!confirm("确定要删除编号 [ "+idList+" ] 的数据嘛?")){
                    return;
                }

                //ajax异步请求
                $.ajax({
                    url:"/history/batchDeleteHistory",
                    data:{"idList":idList},
                    method:"POST",
                    success:function (data,status) {
                        if ("success" == data){
                            alert("批量删除成功~");
                            location.href="/history/listHistory";
                        }else if("fail" == data) {
                            alert("批量删除失败")
                        }else if("error" == data){
                            alert("发生异常~事务回滚")
                        }

                    }

                })
            })
        })

    </script>
</head>
<body>

<div id="viewport" >

    <!-- Sidebar -->
    <div id="sidebar" th:replace="waterMainMenu::sidebar">
        <header>
            <a href="#">公司后台管理</a>
        </header>
        <ul class="nav">
            <li>
                <a >
                    <i class="zmdi zmdi-view-dashboard"></i> 客户管理
                </a>
            </li>
            <li>
                <a>
                    <i class="zmdi zmdi-link"></i> 送水工管理
                </a>
            </li>
            <li>
                <a>
                    <i class="zmdi zmdi-widgets"></i> 送水历史管理
                </a>

        </ul>
    </div>

    <!-- Content -->
    <div id="content" >
        <nav class="navbar navbar-default" th:replace="waterMainMenu::navbar">
            <div class="container-fluid" >
                <ul class="nav navbar-nav navbar-right">
                    <li>
                        <a href="#"><i class="zmdi zmdi-notifications text-danger"></i>
                        </a>
                    </li>
                    <li><a href="#">测试用户123</a></li>
                </ul>
            </div>
        </nav>
        <div class="container-fluid">
            <div class="row">
                <div class="col-md-4">
                    <a type="button" class="btn btn-warning" th:href="@{/history/addHistoryPre}">添加记录</a>
                    <a type="button" class="btn btn-success" id="batchDeleteHistory" href="#">批量删除</a>
                </div>

                <div class="col-md-8">
                    <form class="form-inline" th:action="@{/history/searchHistory}">
                        <label class="list-inline" >开始时间</label>
                        <div class="form-group">
                            <input type="date" class="form-control" name="sendWaterTimeStart">
                        </div>
                        <label class="list-inline">结束时间</label>
                        <div class="form-group" >
                            <input type="date" class="form-control" name="sendWaterTimeEnd">
                        </div>
                        <input type="submit" class="btn btn-info" value="查询">
                    </form>
                </div>


                <div class="col-md-12">
                    <table class="table table-hover table-striped">
                        <thead>
                        <tr>
                            <td>
                                <input type="checkbox" id="selectAll">全选/全否
                            </td>
                            <td>记录编号</td>
                            <td>工人名称</td>
                            <td>送水时间</td>
                            <td>客户名称</td>
                            <td>送水数量</td>
                            <td>操作</td>
                        </tr>
                        </thead>
                        <tbody>
                            <!-- 渲染后客户列表-->
                            <tr th:each="history:${historyList}">
                                <td>
                                    <input type="checkbox" name="chkHistory" th:value="${history.hid}" id="select">
                                </td>
                                <td th:text="${history.hid}"></td>
                                <td th:text="${history.worker.workerName}"></td>
                                <td th:text="${#dates.format(history.sendWaterTime,'yyyy-MM-dd')}"></td>
                                <td th:text="${history.customer.custName}"></td>
                                <td th:text="${history.sendWaterCount}"></td>
                                <td>
                                    <a type="button" class="btn btn-primary" th:href="@{'/history/modHistoryPre/'+${history.hid}}" >修改</a>
                                    <a type="button" class="btn btn-danger" th:href="@{'/history/delHistory/'+${history.hid}}" >删除</a>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>


</body>
</html>